#include "libwifiparty/libwifiparty.hpp"
#include "party-protocol/party-protocol.hpp"
#include <asm-generic/socket.h>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <pulse/context.h>
#include <pulse/def.h>
#include <pulse/error.h>
#include <pulse/mainloop-api.h>
#include <pulse/mainloop.h>
#include <pulse/pulseaudio.h>
#include <pulse/sample.h>
#include <pulse/stream.h>
#include <ratio>
#include <sys/socket.h>
#include <chrono>
#include <unistd.h>
#include <fstream>
#include <unistd.h>
#include <signal.h>
enum channel_ids
{
    music = 1,
    vocal = 2,
    sync_channel = 3,
};
int main(){
    int s = socket(AF_INET, SOCK_DGRAM, 0);
    int flag = 1;
    std::ofstream music_channel_file,vocal_channel_file;
    music_channel_file.open("music_channel.pcm",std::ios::binary|std::ios::out);
    vocal_channel_file.open("vocal_channel.pcm", std::ios::binary | std::ios::out);
    Receiver *receiver = new Receiver(s);
    // Mixer<Trackreceiver> *trackMixer = new Mixer<Trackreceiver>;
    // Trackreceiver *musicTrack = new Trackreceiver();
    // Trackreceiver *vocalTrack = new Trackreceiver();
    // trackMixer->addSource(musicTrack);
    // trackMixer->addSource(vocalTrack);
    Channel *music_channel = new Channel(music, channel_unreliable, 1, s, [&](Packet *p){
            // musicTrack->receiveSound(p);
            music_channel_file.write((char*)p->content.addr,p->content.length);
            music_channel_file.flush();
            return true; });
    Channel *vocal_channel = new Channel(vocal, channel_unreliable, 1, s, [&](Packet *p){
            // vocalTrack->receiveSound(p);
            vocal_channel_file.write((char*)p->content.addr, p->content.length);
            music_channel_file.flush();
            return true; });
    receiver->addChannel(music_channel);
    receiver->addChannel(vocal_channel);

    receiver->receive_blocking();
}
